import { createRouter, createWebHistory } from 'vue-router'
import {useUserStore} from "@/store/userStore.js";


const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/home',
    name: 'home',
    component: () => import ("@/views/home/index.vue")
  },
  {
    path: '/stableDiffusionXl',
    name: 'stableDiffusionXl',
    component: () => import ("@/views/home/stable-diffusion-xl.vue")
  },
  {
    path: '/stableDiffusionXlSd',
    name: 'stableDiffusionXlSd',
    component: () => import ("@/views/home/stable-diffusion-xl-sd.vue")
  },
  {
    path: '/login',
    name: 'login',
    component: () => import ("@/views/user/login.vue")
  },
  {
    path: '/register',
    name: 'register',
    component: () => import ("@/views/user/register.vue")
  },
  {
    path: '/textTovoice',
    name: 'textTovoice',
    component: () => import ("@/views/function/textTovoice.vue")
  },
  {
    path: '/voiceTotext',
    name: 'voiceTotext',
    component: () => import ("@/views/function/voiceTotext.vue")
  }
]

const Router = createRouter({
  history: createWebHistory(import.meta.env.VITE_PUBLIC_PATH),
  routes: routes
})

Router.beforeEach((to, from) => {
  // if(['/login', '/register'].indexOf(to.path) == -1) {
  //   const userStore = useUserStore();
  //   if(!userStore.userinfo) {
  //     return {
  //       path: '/login'
  //     }
  //   }
  // }

  return true;
})

export default Router